<template>
    <ul class="switches">
      <li class="switch-item"
          v-for="(item, index) in switches" :key="item.id" :class="{'active': currentIndex === index}"
      @click="switchIndex(index)">
        <span>{{item.name}}</span>
      </li>
    </ul>
</template>

<script>
    export default {
        name: 'switches',
        props:{
          switches:{
            type:Array
          },
          currentIndex:{
            type:Number,
            default:0
          }
        },
        methods:{
          switchIndex(index){
            this.$emit('switch',index)
          }
        }
    }
</script>

<style lang="scss" scoped>
  @import "./../common/scss/variable";

  .switches{
    display: flex;
    align-items: center;//flex内容居中对齐
    width: 240px;
    margin: 0 auto;
    .switch-item{
      flex: 1;
      padding: 8px;
      margin: 0 20px;
      text-align: center;
      font-size: $font-size-medium;
      color: $color-text-l;
      border-bottom: 2px solid $color-theme;
      &.active{
        border-bottom: 2px solid $color-text-l;
        color: #fff;
      }
    }
  }

</style>
